/*
 * This file is part of Nest.
 * Nest - http://transmote.com/nest/ is a
 * derivative of Processing - http://processing.org/ 
 * Copyright (C) 2011, Eric Socolofsky
 * 
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

package com.transmote.nest.events;

import java.awt.geom.Point2D;

/**
 * <p>
 * MouseEvent instances represent events dispatched by the Nest framework,
 * which wrap the processing.event.Event instances generated by Processing. 
 * </p>
 * 
 * @author		Eric Socolofsky
 * @see			Event
 * @see			EventDispatcher
 */
public class MouseEvent extends Event {
	public static final int MOUSE_CLICKED = processing.event.MouseEvent.CLICK;
	public static final int MOUSE_ENTERED = processing.event.MouseEvent.ENTER;
	public static final int MOUSE_EXITED = processing.event.MouseEvent.EXIT;
	public static final int MOUSE_PRESSED = processing.event.MouseEvent.PRESS;
	public static final int MOUSE_RELEASED = processing.event.MouseEvent.RELEASE;
	public static final int MOUSE_DRAGGED = processing.event.MouseEvent.DRAG;
	public static final int MOUSE_MOVED = processing.event.MouseEvent.MOVE;
	
	private processing.event.MouseEvent pMouseEvent;
	
	/**
	 * A Nest mouse event instance,
	 * generated automatically by the Nest framework.
	 * 
	 * @param	pEvent		This MouseEvent instance will wrap a
	 * 						processing.event.MouseEvent, passed in from PApplet.
	 */
	public MouseEvent (processing.event.MouseEvent pEvent) {
		super(pEvent.getAction());
		
		this.pEvent = pEvent;
		this.pMouseEvent = pEvent;
	}
	
	/**
	 * A Nest mouse event instance.
	 * 
	 * @param	type	The event type.  Equivalent to processing.event.MouseEvent.getAction().
	 */
	public MouseEvent (int type) {
		super(type);
	}
	
	/**
	 * The location of the mouse relative to the PApplet.
	 * Returns null if not available
	 * (e.g. the MouseEvent was not generated in response to a mouse action),
	 * else returns mouse coordinates as a Point2D.Float instance.
	 */
	public Point2D.Float getPoint () {
		if (pMouseEvent == null) { return null; }
		return new Point2D.Float(pMouseEvent.getX(), pMouseEvent.getY());
	}
	
	/**
	 * The processing MouseEvent instance generated by Processing,
	 * if applicable (if this MouseEvent instance was generated
	 * in response to a mouse action captured and processed by PApplet).
	 */
	public processing.event.MouseEvent pMouseEvent () {
		return pMouseEvent;
	}
	
	//-----<PROCESSING API>------------------------------------------//
	public int getX () {
		return pMouseEvent.getX();
	}
	
	public int getY () {
		return pMouseEvent.getY();
	}
	
	public int getButton () {
		return pMouseEvent.getButton();
	}
	
	public int getCount () {
		return pMouseEvent.getCount();
	}
	//-----</PROCESSING API>-----------------------------------------//
}